import Vuex from 'vuex'
import {loginIn} from "../api";
const user={
    namespaced:true,
    state:{
        userId:'',
        username:'',
        photo:'',
        score:'',

    },
    getters:{

        userId: state => {
            let userId=state.userId
            if(!userId){
                userId=JSON.parse(window.sessionStorage.getItem('userId'))
            }
            return activeName
        },
        username: state=>{
            let username=state.username
            if (!username){
                username=JSON.parse(window.sessionStorage.getItem('username'))
            }
            return username
        },
        photo: state=>{
            let photo=state.photo
            if (!photo){
                photo=JSON.parse(window.sessionStorage.getItem('photo'))
            }
            return photo
        },
        score: state=>{
            let score=state.score
            if (!score){
                score=JSON.parse(window.sessionStorage.getItem('score'))
            }
            return score
        },
     },

    mutations:{
        setUserId:(state,userId)=>{
            state.userId=userId
            window.sessionStorage.setItem('userId',JSON.stringify(userId))
        },
        setUsername:(state,username)=>{
            state.username=username
            window.sessionStorage.setItem('username',JSON.stringify(username))
        },
        setPhoto:(state,photo)=>{
            state.photo=photo
            window.sessionStorage.setItem('photo',JSON.stringify(photo))
        },
        setScore:(state,score)=>{
            state.score=score
            window.sessionStorage.setItem('score',JSON.stringify(score))
        },
    }

}
export default user